package com.liy.framework.common.web.controller;

import com.liy.framework.common.extvo.LoginInfo;
import com.liy.framework.common.utils.ContextHandler;
import java.util.List;
import java.util.Locale;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.servlet.support.RequestContextUtils;


public class SupportController {
    protected static Logger log = LoggerFactory.getLogger(SupportController.class);

    @Autowired
    protected HttpServletRequest request;

    @Autowired
    protected HttpServletResponse response;

    @Autowired
    private MessageSource messageSource;


    protected LoginInfo getLoginUser() {
        return ContextHandler.getLoginUser();
    }

    protected List<String> getRoleList() {
        return this.getLoginUser().getRoles(this.getStationNo());
    }

    protected boolean isSuperAdminLogin() {
        return "SA".equals(this.getLoginUser().getUserType());
    }

    protected String getStationNo() {
        return this.request.getHeader("StationId");
    }

    protected String getLoginUserId() {
        return this.getLoginUser().getId();
    }

    protected String getJwtToken() {
        return ContextHandler.getJwtToken();
    }

    protected String getAuthorization() {
        return ContextHandler.getAuthKey();
    }

    protected Object getCurrentAttr(String key) {
        return ContextHandler.get(key);
    }

    protected String getRequestParameter(String key) {
        return this.request.getParameter(key);
    }

    protected String getMessage(String key) {
        Locale locale = RequestContextUtils.getLocale(this.request);
        return this.messageSource.getMessage(key, (Object[])null, locale);
    }
}
